﻿using CommunityToolkit.Mvvm.ComponentModel;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Media;
using UltrasoundTestingProject.SeedDatas;
using Wpf_Demo;

namespace UltrasoundTestingProject.ViewModels
{
    /// <summary>
    /// B扫
    /// </summary>
    public partial class BScanViewModel : ObservableObject
    {
        public BScanViewModel()
        {
            rectangles = new();
            // 取颜色
            for (int i = 0; i < SeedData.list.Count; i++)
            {
                var values = SeedData.list[i];   //  从颜色数据中取颜色
                                                 //var colors = ColorConvertHelper.RgbFrom(values);

                RectanglePositionList rectanglePositions = new();
                for (int j = 0; j < values.Count; j++)
                {
                    var number = values[j];
                    var color = XmlHelper.Instancen.GetColor(number);

                    // 创建并添加矩形表示点
                    RectangleShpare rectangle = new RectangleShpare
                    {
                        Width = 2.5,
                        Height = 2.5,
                        Fill = new SolidColorBrush(System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B)),
                        Visibility = Visibility.Visible
                    };

                    rectanglePositions.RectanglePosition.Add(rectangle);
                }
                rectangles.Add(rectanglePositions);
            }
        }

        [ObservableProperty]
        public ObservableCollection<RectanglePositionList> rectangles;
    }
}

public class RectanglePositionList
{
    public List<RectangleShpare> RectanglePosition { get; set; } = new();
}

public class RectangleShpare
{
    public double Width { get; set; }
    public double Height { get; set; }
    public SolidColorBrush Fill { get; set; }
    public Visibility Visibility { get; set; }
}